package com.sanda.androidcourse.strategy.mvvm;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.sanda.androidcourse.strategy.model.CalculatorModel;

// ViewModel
public class CalculatorViewModel extends ViewModel {
    public MutableLiveData<String> num1 = new MutableLiveData<>();
    public MutableLiveData<String> num2 = new MutableLiveData<>();
    public MutableLiveData<String> result = new MutableLiveData<>();

    private CalculatorModel model = new CalculatorModel();

    public void add() {
        int a = Integer.parseInt(num1.getValue());
        int b = Integer.parseInt(num2.getValue());
        int res = model.add(a, b);
        result.setValue("结果: " + res);
    }
}
